@using Orchard.ContentManagement.Metadata.Settings;
@inject Orchard.ContentManagement.MetaData.IContentDefinitionManager ContentDefinitionManager

@{
    var contentType = ContentDefinitionManager.GetTypeDefinition((string)Model.ContentItem.ContentType).DisplayName;
    var widgetContentTypes = ContentDefinitionManager.ListTypeDefinitions().Where(t => t.Settings.ToObject<ContentTypeSettings>().Stereotype == "Widget");
}

<div class="widget widget-editor card my-1 @(Model.Inline != true ? "collapsed" : "")">
    <div class="widget-editor-header card-header text-muted">
        <button type="button" class="btn btn-outline-secondary btn-sm widget-editor-btn-toggle widget-editor-btn-collapse"><i class="fa fa-minus" aria-hidden="true"></i></button>
        <button type="button" class="btn btn-outline-secondary btn-sm widget-editor-btn-toggle widget-editor-btn-expand"><i class="fa fa-plus" aria-hidden="true"></i></button>
        @contentType
        <div class="btn-group btn-group-sm float-right" role="group">
            <div class="btn-group">
                <button type="button" title="@T["Insert Widget"]" class="btn btn-secondary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i class="fa fa-plus" aria-hidden="true"></i>
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                    @foreach (var type in widgetContentTypes)
                    {
                        <a 
                           class="dropdown-item insert-widget btn-sm" 
                           data-target-id="@Model.TargetId" 
                           data-prefixes-name="@Model.PrefixesName"
                           data-flowmetadata="false"
                           data-contenttypes-name="@Model.ContentTypesName"
                           data-widget-type="@type.Name" 
                           href="javascript:;">@type.DisplayName</a>
                    }
                </div>
            </div>
            <button type="button" class="btn btn-secondary widget-delete" itemprop="RemoveUrl"><i class="fa fa-trash" aria-hidden="true"></i></button>
        </div>
    </div>
    <div class="widget-editor-body card-block">
        <div class="col-12">
        @if (Model.Content != null)
        {
            @await DisplayAsync(Model.Content)
        }
        @if (Model.Parts != null)
        {
            @await DisplayAsync(Model.Parts)
        }
        </div>
    </div>
    <div class="widget-editor-footer card-footer  text-muted">
        @if (Model.Footer != null)
        {
            @await DisplayAsync(Model.Footer)
        }
    </div>
</div>
